﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="List.aspx.cs" Inherits="SysAdmin_Template_News_List" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
</head>
<body>
    <script type="text/javascript">
        $(function () {
            $('#site_model_news_list_<%=news_code %>').datagrid({
                url: 'Template/News/List.aspx?paramType=QueryList&news_code=' + "<%=news_code %>",
                fit: true,
                fitColumns: true,
                border: false,
                pagination: true,
                idField: 'NewsKey',
                pageSize: 30,
                pageList: [10, 20, 30, 40, 50],
                sortName: 'text',
                sortOrder: 'asc',
                checkOnSelect: false,
                selectOnCheck: false,
                nowrap: false,
                frozenColumns: [[{
                    title: '编号',
                    field: 'NewsKey',
                    width: 150,
                    sortable: true,
                    checkbox: true
                }, {
                    title: '标题',
                    field: 'Title',
                    width: 150,
                    sortable: true
                }]],
                columns: [[{
                    title: '作者',
                    field: 'Author',
                    width: 300,
                    hidden: true
                }, {
                    title: '来源',
                    field: 'NewSource',
                    width: 300,
                    formatter: function (value, row, index) {
                        if (row.id == '0') {
                            return '可访问系统所有资源';
                        } else {
                            return value;
                        }
                    }
                },
                {
                    title: '创建时间',
                    field: 'temp_createtime',
                    width: 300,
                    formatter: function (value, row, index) {
                        if (row.id == '0') {
                            return '可访问系统所有资源';
                        } else {
                            return value;
                        }
                    }
                }, {
                    field: 'action',
                    title: '动作',
                    width: 100,
                    formatter: function (value, row, index) {
                        return formatString('<img onclick="sysadmin_template_news_edit_<%=news_code %>(\'{0}\');" src="{1}"/>&nbsp;<img onclick="sysadmin_template_news_del_<%=news_code %>(\'{2}\');" src="{3}"/>', row.NewsKey, 'Images/pencil.png', row.NewsKey, 'Images/cancel.png');
                    }
                }]],
                toolbar: [{
                    text: '增加',
                    iconCls: 'icon-add',
                    handler: function () {
                        sysadmin_template_news_add_<%=news_code %>();
                    }
                }, '-', {
                    text: '批量删除',
                    iconCls: 'icon-remove',
                    handler: function () {
                        sysadmin_template_news_delMultiple_<%=news_code %>();
                    }
                }, '-']
            });

        });

        //添加新闻
        function sysadmin_template_news_add_<%=news_code %>() {
            //$('#admin_jsgl_datagrid').datagrid('uncheckAll').datagrid('unselectAll').datagrid('clearSelections');
            $('<div/>').dialog({
                href: 'Template/News/Add.aspx?new_type=' + "<%=news_code %>",
                width: 800,
                height: 600,
                modal: true,
                title: '添加新闻',
                buttons: [{
                    text: '增加',
                    iconCls: 'icon-add',
                    handler: function () {
                        var d = $(this).closest('.window-body');
                        $('#site_model_news_add_<%=news_code%>').form('submit', {
                            url: 'Template/News/List.aspx?paramType=AddModel&news_code=' + "<%=news_code %>",
                            success: function (result) {
                                try {
                                    var r = $.parseJSON(result);
                                    if (r.success) {
                                        $('#news_file_upload_<%=news_code%>').uploadify('destroy');
                                        $('#news_file_att_<%=news_code%>').uploadify('destroy')
                                        d.dialog('destroy');
                                        $('#site_model_news_list_<%=news_code %>').datagrid('load', {});
                                        $.messager.show({
                                            title: '提示',
                                            msg: r.msg
                                        });
                                    }

                                } catch (e) {
                                    $.messager.alert('提示', result);
                                }
                            }
                        });
                    }
                }],
                onClose: function () {
                    $('#news_file_upload_<%=news_code%>').uploadify('destroy');
                    $('#news_file_att_<%=news_code%>').uploadify('destroy')
                    $(this).dialog('destroy');
                }
            });
        }

        //编辑新闻
        function sysadmin_template_news_edit_<%=news_code %>(news_key) {
            //$('#admin_jsgl_datagrid').datagrid('uncheckAll').datagrid('unselectAll').datagrid('clearSelections');
            $('<div/>').dialog({
                href: 'Template/News/Edit.aspx?news_key=' + news_key,
                width: 800,
                height: 600,
                modal: true,
                title: '编辑新闻',
                buttons: [{
                    text: '编辑',
                    iconCls: 'icon-edit',
                    handler: function () {
                        var d = $(this).closest('.window-body');
                        $('#site_model_news_edit_<%=news_code %>').form('submit', {
                            url: 'Template/News/List.aspx?paramType=UpdateModel&&news_code=<%=news_code %>',
                            success: function (result) {
                                d.dialog('destroy');
                                try {
                                    var r = $.parseJSON(result);
                                    if (r.success) {
                                        $('#news_edit_img_upload_<%=news_code%>').uploadify('destroy');
                                        $('#news_edit_att_<%=news_code%>').uploadify('destroy')
                                        $('#site_model_news_list_<%=news_code %>').datagrid('load', {});
                                        $.messager.show({
                                            title: '提示',
                                            msg: r.msg
                                        });
                                    }

                                } catch (e) {
                                    $.messager.alert('提示', result);
                                }
                            }
                        });
                    }
                }],
                onClose: function () {
                    $('#news_edit_img_upload_<%=news_code%>').uploadify('destroy');
                    $('#news_edit_att_<%=news_code%>').uploadify('destroy')
                    $(this).dialog('destroy');
                }
            });
        }

        //删除新闻
        function sysadmin_template_news_del_<%=news_code %>(news_key) {
            $.messager.confirm('提示', '你确定要删除该行数据么?', function (r) {
                if (r) {
                    $.ajax({
                        type: "POST",
                        url: 'Template/News/List.aspx?news_code=' + "<%=news_code %>",
                        data: "paramType=DelModel&news_key=" + news_key,
                        dataType: "json",
                        success: function (msg) {
                            if (msg.success) {
                                $('#site_model_news_list_<%=news_code %>').datagrid('load', {});
                            }
                        },
                        error: function (e, ex) {
                            $.messager.alert('错误提示', '删除失败！');
                        }

                    });
                }
            });
        }

    </script>
    <table id="site_model_news_list_<%=news_code %>"></table>
</body>
</html>
